<?php
class FormcategoryAction extends IntesysAction{
	function _initialize(){
        parent::_initialize();
		$this->dao = D('Formcategory');// 编辑、删除操作需要
    }
	//分类管理列表
    public function index(){
		$this->listmap = 'site_id = '.__SITEID__;
		$this->pagesize = 20;
		parent::_list();
		$this->display();
	}
	
	public function getcategory(){
		$this->list = $this -> dao -> where(array('site_id' => __SITEID__)) -> order('id desc') -> select();
		$this->display();
	}
	
	public function insert(){
		//$_POST['member_id'] = $this->memberInfo['id'];
		$_POST['site_id'] = __SITEID__;
		parent::insert();
	}
	public function tree(){
		$pid = $this->_get('pid') ? $this->_get('pid') : 0;
		$this->listmap.=" and site_id = '".__SITEID__."' and pid=".$pid;
		$this->listorder = 'sort';
		if($this->_param('keywords')){
			$keywords=$this->_param('keywords');
			$_GET['keywords']=urlencode($this->_param('keywords'));
			$this->listmap.=" and (title like '%{$keywords}%' or name like '%{$keywords}%')";
			$this->keywords=$keywords;
		}
		
		$this->initView();
        parent::_list();
		$list=$this->list;
		
		$this->assign('list',$list);
		$str = $this->fetch();
		$list = $this->view -> get('list');
		foreach($list as $k => $v){
			$str = str_replace('<!--sub#'.$v['id'].'-->', $this->treehtml($v['id']), $str);
		}
		
		$list = $_GET['list'];
		$empty = 1;
		$statu=$list?1:0;
		if($this->get('list')){
			$empty = 0;
		}
		
		die(json_encode(array('empty' => $empty,'tbody'=>$str,'dump'=>$_REQUEST,'statu'=>$statu, 'pages' => $this-> view -> get('pages'))));
	}
	private function treehtml($pid = 0){
		$list = $this->dao -> where(array('site_id' => __SITEID__, 'pid' => $pid)) -> order('sort') -> select();
		if($list){
			$this->assign('list', $list);
			$curstr = $this->fetch('tree');
			foreach($this->list as $k => $v){
			    $curstr = str_replace('<!--sub#'.$v['id'].'-->', $this->treehtml($v['id']), $curstr);
		    }
			return $curstr; 
		}
	}
	
	
	
}

